package config;

import java.sql.Connection;
import java.sql.SQLException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
public class EstablishConnection {
	public static Connection conection=null;
	private Context cnt=null;
	private DataSource ds=null;
	private static EstablishConnection econ=null;
	
	private EstablishConnection(){
		try {
			cnt=new InitialContext();
			ds=(DataSource)cnt.lookup("java:comp/env/oracleConnectionPool");
			conection=ds.getConnection();
			System.out.println("Connect Success!");
		} catch (NamingException e) {
			System.out.println("Connect unSuccess!");
			e.printStackTrace();
		}catch (SQLException e) {
			System.out.println("Connect unSuccess!");
			e.printStackTrace();
		}
	}
	public static EstablishConnection CreateInstance(){
		if(econ==null){
			econ=new EstablishConnection();
		}
		return econ;
	}	
}
